package com.example.demo.quartz;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling // 该注解必须要加
@EnableAsync
public class ScheduleTask {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    private int t = 0;

    //@Scheduled(cron="0/4 * * * * ? ")
    public void scheduleTest() {
        for (; ; ) {
            break;//获取到活动，生产活动商品放入缓存，等待消费,可能一个model+goods就是一个list
        }
        //添加活动到redis中
        stringRedisTemplate.opsForHash().put("acitvity", "t1Activity", "t1");


        //还有一个定时任务用来销毁相关活动信息
    }

   // @Scheduled(cron = "0/2 * * * * ? ")
    public void scheduleTest1() {
        t = t + 1;
        if (t % 5 == 0) {
            int r = 1 / 0;
        } else {
            System.out.println("threadName:" + Thread.currentThread().getName() + "scheduleTest1 corn2" + "----t=" + t);
        }

        //还有一个定时任务用来销毁相关活动信息
    }

   // @Scheduled(cron = "0/4 * * * * ? ")
    public void scheduleTest2() {
        t = t + 1;
        if (t % 6 == 0) {
            int r = 1 / 0;
        } else {
            System.out.println("threadName:" + Thread.currentThread().getName() + "scheduleTest2 corn4" + "----t=" + t);
        }

    }

   // @Scheduled(cron = "0/3 * * * * ? ")
    public void scheduleTest3() {
        t = t + 1;
        if (t % 7 == 0) {
            int r = 1 / 0;
        } else {
            System.out.println("threadName:" + Thread.currentThread().getName() + "scheduleTest3 corn3" + "----t=" + t);
        }

    }
}